package kr.salebeans.cm.process.customer.impl;

import kr.salebeans.cm.customer.CustomerRegisterDto;
import kr.salebeans.cm.domain.customer.ContactPoint;
import kr.salebeans.cm.domain.customer.Customer;

class CustomerConverter {
    public static CustomerRegisterDto makeCustomerRegisterDto(Customer customer) {
        if (customer == null) return null;
        CustomerRegisterDto res = new CustomerRegisterDto();
        res.setShopId(customer.getShopId());
        res.setCustomerId(customer.getId());
        res.setCustomerName(customer.getCustomerName());
        res.setGender(customer.getGender());
        res.setRemark(customer.getRemark());

        ContactPoint contactPoint = customer.getContactPoint();
        if (contactPoint != null) {
            res.setPhoneNo1(contactPoint.getPhoneNumber1());
            res.setPhoneNo2(contactPoint.getPhoneNumber2());
            res.setPhoneNo3(contactPoint.getPhoneNumber3());
            res.setCellNo1(contactPoint.getCellPhoneNumber1());
            res.setCellNo2(contactPoint.getCellPhoneNumber2());
            res.setCellNo3(contactPoint.getCellPhoneNumber3());
            res.setEmail(contactPoint.getEmail());
            res.setZipNo1(contactPoint.getZipNo1());
            res.setZipNo2(contactPoint.getZipNo2());
            res.setBaseAddress(contactPoint.getBaseAddress());
            res.setDetailAddress(contactPoint.getDetailAddress());
        }
        return res;
    }

    public static Customer makeCustomer(Customer customer, CustomerRegisterDto customerReqDto) {
        if (customerReqDto == null) return null;
        if (customer == null) customer = new Customer();

        customer.setId(customerReqDto.getCustomerId());
        customer.setCustomerName(customerReqDto.getCustomerName());
        customer.setGender(customerReqDto.getGender());
        customer.setRemark(customerReqDto.getRemark());
        customer.setShopId(customerReqDto.getShopId());

        ContactPoint contactPoint = new ContactPoint();
        contactPoint.setCellPhoneNumber1(customerReqDto.getCellNo1());
        contactPoint.setCellPhoneNumber2(customerReqDto.getCellNo2());
        contactPoint.setCellPhoneNumber3(customerReqDto.getCellNo3());
        contactPoint.setPhoneNumber1(customerReqDto.getPhoneNo1());
        contactPoint.setPhoneNumber2(customerReqDto.getPhoneNo2());
        contactPoint.setPhoneNumber3(customerReqDto.getPhoneNo3());
        contactPoint.setEmail(customerReqDto.getEmail());
        contactPoint.setZipNo1(customerReqDto.getZipNo1());
        contactPoint.setZipNo2(customerReqDto.getZipNo2());
        contactPoint.setBaseAddress(customerReqDto.getBaseAddress());
        contactPoint.setDetailAddress(customerReqDto.getDetailAddress());
        customer.setContactPoint(contactPoint);
        return customer;
    }

}
